#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

"""
@author: JoeyZhou
@Tool: PyCharm
@Date: 2020/2/16 5:06 PM
@desc: 
"""

import os
import time
from os import path
import logging.config
from common.test_report import TestReport
from common.send_email import SendEmail


parent_path = path.os.getcwd()  # 获取当前工作目录路径
CON_LOG = parent_path + '/config/log.conf'  # /Users/zhouyi/project/QA/aihuishou-interface/config/log.conf
logging.config.fileConfig(CON_LOG)
logging = logging.getLogger()


class Run(object):
    def run_main(self):
        tr = TestReport()
        tr.create_detail_report()
        tr.create_email_report()
        time.sleep(3)
        run.send_mail()

    def send_mail(self):
        parent_path = path.dirname(__file__)    # 获得当前文件的父级目录
        reports_path = parent_path + "/reports/email_reports/"
        list_report = os.listdir(reports_path)
        datanames = sorted(list_report, reverse=True)
        list = []
        for dataname in datanames:
            if os.path.splitext(dataname)[1] == '.html':  # 目录下包含.html的文件
                list.append(dataname)
        reports_path = reports_path + list[0]
        se = SendEmail()
        se.send_mail(reports_path)


if __name__ == '__main__':
    run = Run()
    run.run_main()
